<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>



</body>
<script>
    function getTime() {
        // 返回1000~3000的数值
        return Math.floor(Math.random() * 3000 + 1000);
    }


    function buy(user,name) {
        let boo = Math.random() <= 0.5;
        return new Promise((reslove, reject) => {
            setTimeout(() => {
                if (boo) {
                    reslove({user,name});
                } else {
                    reject({user,name});
                }
            },getTime())
        })
    }

    function eat() {
        let promise1 = buy("刘煜鑫","猪肉");
        let promise2 = buy("袁浩哲","鸡肉");
        let promise3 = buy("郑涛","羊肉");

        promise1.then(res => {
            console.log(res.user + "，你很不错，快来吃你买的：" + res.name);
        },res => {
            console.log(res.user + "，连" + res.name + "都买不到，去面壁思过！");
        })

        promise2.then(res => {
            console.log(res.user + "，你很不错，快来吃你买的：" + res.name);
        },res => {
            console.log(res.user + "，连" + res.name + "都买不到，去剃光头吧！");
        })
        
        promise3.then(res => {
            console.log(res.user + "，你很不错，快来吃你买的：" + res.name);
        },res => {
            console.log(res.user + "，连" + res.name + "都买不到，去出家吧！");
        })

    }

    eat();


</script>

</html>